package com.whfc.mach.manager.strategy.work;

import com.whfc.mach.dto.AppMachDaySegDTO;
import com.whfc.mach.enums.WorkState;
import com.whfc.mach.manager.util.MachSegmentUtil;
import com.whfc.mach.manager.util.MachUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @Description: 短时间的停机改为怠机
 * @author: xugcheng
 * @version: 1.0
 * @date: 2020-12-11 15:23
 */
public class FilterStopWorkStrategy implements WorkStrategy {

    private Logger logger = LoggerFactory.getLogger(FilterStopWorkStrategy.class);

    /**
     * 3分钟
     */
    private static final int STOP_TIMES_LIMIT = 3 * 60;

    @Override
    public Integer amend(Integer workState) {
        return workState;
    }

    @Override
    public List<AppMachDaySegDTO> amend(List<AppMachDaySegDTO> segmentList) {

        // 短时间的停机改为怠机
        for (AppMachDaySegDTO segDTO : segmentList) {
            if (MachUtil.isStopState(segDTO.getWorkState()) && segDTO.getTimes() < STOP_TIMES_LIMIT) {
                segDTO.setWorkState(WorkState.IDLE.getValue());
            }
        }
        // 合并相同分段
        List<AppMachDaySegDTO> amendSegList = MachSegmentUtil.mergeMachDaySegment(segmentList);
        logger.info("短时间的停机改为怠机,{}->{}", segmentList.size(), amendSegList.size());
        return amendSegList;
    }
}
